package com.ybkj.daijia.api.weixin.handler.impl;

import com.ybkj.daijia.api.weixin.WxMsgType;
import com.ybkj.daijia.api.weixin.entity.WxBaseMsgEntity;
import com.ybkj.daijia.api.weixin.entity.WxBaseRespEntity;
import com.ybkj.daijia.api.weixin.entity.WxMsgEventEntity;
import com.ybkj.daijia.api.weixin.handler.WxHandler;
import java.util.Map;

public abstract class AbstractWxEventHandler implements WxHandler {

    @Override
    public Integer priority() {

        return 0;
    }


    @Override
    public boolean canHandle(WxBaseMsgEntity msg) {

        if (WxMsgType.valueOf(msg.getMsgType()).compareTo(WxMsgType.event) == 0) {
            return true;
        }

        return false;
    }


    @Override
    public final WxBaseRespEntity doHandle(WxBaseMsgEntity msg, Map<String, Object> context,
        WxBaseRespEntity resp) {

        if (WxMsgType.valueOf(msg.getMsgType()).compareTo(WxMsgType.event) == 0) {

            return handleEvent((WxMsgEventEntity) msg, context, resp);

        }

        return resp;
    }

    /**
     * 处理事件消息
     *
     * @param msg
     * @param context
     * @return
     */
    public abstract WxBaseRespEntity handleEvent(WxMsgEventEntity msg, Map<String, Object> context,
        WxBaseRespEntity resp);

}
